#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/6/24 23:03
# @Author  : sailor233
# @File    : webDriverWait_Advanced.py
# @Software: PyCharm
# @Des     :
from time import sleep

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome()
driver.get('https://vip.ceshiren.com/#/ui_study/frame')
driver.maximize_window()

def element_to_be_clickable(target_ele, next_ele):
    """
    点击目标元素，返回点击后出现的新元素，没有则返回None
    :param target_ele: 需要点击的目标元素,如：(By.ID, "primary_btn"),传入的是一个元组
    :param next_ele: 点击目标元素的后需要返回的新元素：
    :return:
    """
    def _predicate(driver):
        # 点击目标元素
        driver.find_element(*target_ele).click()
        # 返回期待的下一个元素，不存在时返回None
        return driver.find_element(*next_ele)

    return _predicate

WebDriverWait(driver, 10).until(
    element_to_be_clickable((By.ID, "primary_btn"),
                            (By.XPATH,'//*[text()="该弹框点击两次后才会弹出"]'))
)

sleep(5)
